from flask import Flask
from werkzeug.middleware.dispatcher import DispatcherMiddleware
from werkzeug.serving import run_simple
# pip install werkzeug
from apps.admin import app as admin_app
from apps.index import app as index_app
from config import SERVER_HOST, SERVER_PORT, DEBUG

app = Flask(__name__)
app.secret_key = 'topLevel'


@app.route('/')
def index():
    return 'Hello top level!'


dm = DispatcherMiddleware(index_app, {
    '/index': index_app,
    '/admin': admin_app,
})
# 默认使用app01的路由，也就是访问 http://127.0.0.1:5000/index 返回app01
# 当以app01开头时候使用app01的路由，也就是http://127.0.0.1:5000/index/index 返回app01
# 当以app02开头时候使用app02的路由，也就是http://127.0.0.1:5000/admin/index 返回app02

if __name__ == "__main__":
    run_simple(SERVER_HOST, SERVER_PORT, dm)
